package com.adam.springmvc.service;

import com.adam.springmvc.dao.StudentDAO;
import com.adam.springmvc.domain.Student;
import com.adam.springmvc.mapper.StudentMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StudentService {

    private final Logger logger = LoggerFactory.getLogger(StudentService.class);

    @Autowired
    private StudentMapper studentMapper;
    @Autowired
    private StudentDAO studentDAO;

    public List<Student> findAllStudents() {
        logger.debug("findAllStudents");
        return studentMapper.findAllStudents();
    }

    public Student findStudentById(int studId) {
        logger.debug("findStudentById:{}", studId);
        return studentDAO.findStudentById(studId);
    }

    public int insertStudent(Student student) {
        logger.debug("insertStudent:{}", student);
        int i = studentMapper.insertStudent(student);
        logger.debug("insertStudent result:{} {}",i,student);
        return i;
    }

}
